In [4]:
import IPython
c = IPython.parallel.Client()
dv = c[0]
dv.block = True
dv.activate()
with dv.sync_imports():
import pickle
import numpy
from nc_ipython import ncserialisable
In [1]:
from nc_ipython import ncserialisable
In [3]:
d = ncserialisable.Dataset('data', 'w', format = 'NETCDF4')
try:
g = d.createGroup('g')
t = numpy.dtype(numpy.float64)
t = g.createVLType(t, 't')
x, y, z = 50, 30, 20
g.createDimension('x', x)
g.createDimension('y', y)
g.createDimension('z', z)
w = g.createVariable('w', t, ('x'))
v = g.createVariable('v', 'f8', ('x', 'y', 'z'))
for i in xrange(x):
for j in xrange(y):
v[i,j,:] = numpy.random.random(z)
finally:
d.close()
In [17]:
d = ncserialisable.Dataset('data', 'w', format = 'NETCDF3_64BIT')
try:
x, y, z = 5, 3, 2
d.createDimension('x', x)
d.createDimension('y', y)
d.createDimension('z', z)
v = d.createVariable('v', 'f8', ('x', 'y', 'z'))
for i in xrange(x):
for j in xrange(y):
v[i,j,:] = numpy.random.random(z)
finally:
d.close()
In [32]:
reload(ncserialisable)
%px reload(ncserialisable)
In [33]:
def f (w):
v = w.group().variables['v']
rtn = (v[:].sum() / v.size, v.size, w.dtype)
w.group().parent.close()
return rtn
d = ncserialisable.Dataset('data', 'r')
try:
g = d.groups['g']
w = g.variables['w']
print dv.apply(f, w)
finally:
try:
d.close()
except RuntimeError:
pass